import { Collection, EntitySchema } from '@mikro-orm/core';
import { ChatRooms } from './ChatRooms';
import { JobProjectSources } from './JobProjectSources';
import { JobTasks } from './JobTasks';
import { OfficeAccounts } from './OfficeAccounts';
import { OfficeNewsSendRecords } from './OfficeNewsSendRecords';
import { OfficePosts } from './OfficePosts';
import { OrderJobEnrolls } from './OrderJobEnrolls';
import { WechatAppid } from './WechatAppid';

export class Users {
  id!: string;
  createdAt?: Date;
  updatedAt?: Date;
  email?: string;
  emailVerifiedAt?: Date;
  password?: string;
  rememberToken?: string;
  modules!: any;
  roles!: any;
  headIconUrl?: string;
  sex?: string;
  shortText?: string;
  nickname!: string;
  name?: string;
  idNumber?: string;
  phoneNumber?: string;
  phoneVerifiedAt?: Date;
  bankAddress?: string;
  bankAccount?: string;
  bankNumber?: string;
  address?: string;
  wxNumber?: string;
  wxQcode?: string;
  idCardFrontUrl?: string;
  idCardBackUrl?: string;
  idAuthenticatedAt?: string;
  money?: string;
  accounts = new Collection<OfficeAccounts>(this);
  roomsAsChatRoomMembers = new Collection<ChatRooms>(this);
  sourcesAsCreator = new Collection<JobProjectSources>(this);
  sourcesAsOwner = new Collection<JobProjectSources>(this);
  tasksAsCreator = new Collection<JobTasks>(this);
  tasksAsOwner = new Collection<JobTasks>(this);
  records = new Collection<OfficeNewsSendRecords>(this);
  posts = new Collection<OfficePosts>(this);
  enrollsAsEnroller = new Collection<OrderJobEnrolls>(this);
  enrollsAsAgent = new Collection<OrderJobEnrolls>(this);
  enrollsAsSalaryGiver = new Collection<OrderJobEnrolls>(this);
  appid = new Collection<WechatAppid>(this);
}

export const UsersSchema = new EntitySchema({
  class: Users,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    createdAt: { type: 'Date', length: 0, nullable: true },
    updatedAt: { type: 'Date', length: 0, nullable: true },
    email: { type: 'string', length: 255, nullable: true, unique: 'users_email_unique' },
    emailVerifiedAt: { type: 'Date', length: 0, nullable: true },
    password: { type: 'string', length: 255, nullable: true },
    rememberToken: { type: 'string', length: 100, nullable: true },
    modules: { type: 'any', columnType: 'json' },
    roles: { type: 'any', columnType: 'json' },
    headIconUrl: { type: 'string', length: 255, nullable: true },
    sex: { type: 'string', length: 10, nullable: true },
    shortText: { type: 'string', length: 255, nullable: true },
    nickname: { type: 'string', length: 255 },
    name: { type: 'string', length: 255, nullable: true },
    idNumber: {
      type: 'string',
      length: 255,
      nullable: true,
      unique: 'users_id_number_unique',
    },
    phoneNumber: {
      type: 'string',
      length: 255,
      nullable: true,
      unique: 'users_phone_number_unique',
    },
    phoneVerifiedAt: { type: 'Date', length: 0, nullable: true },
    bankAddress: { type: 'string', length: 500, nullable: true },
    bankAccount: { type: 'string', length: 255, nullable: true },
    bankNumber: { type: 'string', length: 255, nullable: true },
    address: { type: 'string', length: 255, nullable: true },
    wxNumber: { type: 'string', length: 255, nullable: true },
    wxQcode: { type: 'string', length: 255, nullable: true },
    idCardFrontUrl: { type: 'string', length: 255, nullable: true },
    idCardBackUrl: { type: 'string', length: 255, nullable: true },
    idAuthenticatedAt: { type: 'string', length: 255, nullable: true },
    money: { type: 'string', columnType: 'double', nullable: true },
    accounts: { reference: '1:m', entity: () => OfficeAccounts, mappedBy: 'owner' },
    roomsAsChatRoomMembers: { reference: 'm:n', entity: () => ChatRooms, mappedBy: 'chatRoomMembers' },
    sourcesAsCreator: { reference: '1:m', entity: () => JobProjectSources, mappedBy: 'creator' },
    sourcesAsOwner: { reference: '1:m', entity: () => JobProjectSources, mappedBy: 'owner' },
    tasksAsCreator: { reference: '1:m', entity: () => JobTasks, mappedBy: 'creator' },
    tasksAsOwner: { reference: '1:m', entity: () => JobTasks, mappedBy: 'owner' },
    records: { reference: '1:m', entity: () => OfficeNewsSendRecords, mappedBy: 'creator' },
    posts: { reference: '1:m', entity: () => OfficePosts, mappedBy: 'creator' },
    enrollsAsEnroller: { reference: '1:m', entity: () => OrderJobEnrolls, mappedBy: 'enroller' },
    enrollsAsAgent: { reference: '1:m', entity: () => OrderJobEnrolls, mappedBy: 'agent' },
    enrollsAsSalaryGiver: { reference: '1:m', entity: () => OrderJobEnrolls, mappedBy: 'salaryGiver' },
    appid: { reference: '1:m', entity: () => WechatAppid, mappedBy: 'owner' },
  },
});
